import pyglet

class Hud(object):
    def __init__(self,g):
        self.g=g
        self.showfps=False
        self.fps=pyglet.clock.ClockDisplay()        
        self.heart=g.LoadStaticImg('hud/heart.png')
        self.score=g.LoadStaticImg('hud/score.png')
        self.screen=g.LoadImg('hud/screen.png')
        self.heart.set_position(self.g.width-120,24)
        self.score.set_position(32,self.g.height-24)
        self.screen.set_position(self.g.width//2,self.g.height//2)
        self.l_pause=self.Label('paused',60,self.g.width//2,self.g.height//2)
        self.l_gameover=self.Label('game over',60,self.g.width//2,self.g.height//2)
        self.l_fvs=self.Label("freevryheid's",32,self.g.width//2,self.g.height-20)
        self.l_cont=self.Label('click to continue',32,self.g.width//2,32)
        h=32
        self.l_end1=self.Label('pygBricks by freevryheid',20,self.g.width//2,self.g.height-h)
        h+=32
        self.l_end2=self.Label('a turnsun production',20,self.g.width//2,self.g.height-h)
        h+=64
        self.l_end3=self.Label('thanks to:',20,self.g.width//2,self.g.height-h)
        h+=32
        self.l_end4=self.Label('pygleters everywhere',20,self.g.width//2,self.g.height-h)
        h+=32
        self.l_end5=self.Label('mod musicians',20,self.g.width//2,self.g.height-h)
        h+=32
        self.l_end6=self.Label('http://modarchive.org/',20,self.g.width//2,self.g.height-h)
        h+=32
        self.l_end7=self.Label('Ian Luck for BASS',20,self.g.width//2,self.g.height-h)
        h+=32
        self.l_end8=self.Label('google',20,self.g.width//2,self.g.height-h)
        h+=64
        self.l_end9=self.Label('dedicated to jilly',20,self.g.width//2,self.g.height-h)
        h+=32
        self.l_end10=self.Label('- THE END -',20,self.g.width//2,self.g.height-h)
        self.l_level=None
        self.l_lives=None
        self.l_score=None


    def Label(self,txt,size,x,y):
        return pyglet.text.Label(txt,font_name='Beware',font_size=size,x=x,y=y,anchor_x='center',anchor_y='center')

    def LabelLevel(self):
        self.l_level=self.Label('level '+str(self.g.nlvl),60,self.g.width//2,self.g.height//2)

    def LabelLives(self):
        if self.g.lives==0:
            self.g.state &= ~self.g.PLAY
            self.g.state |= self.g.GAMEOVER
        self.l_lives=self.Label(str(self.g.lives),36,self.g.width-48,40)

    def LabelScore(self):
        if self.g.score<0: self.g.score=0
        self.l_score=self.Label(str(self.g.score),36,150,self.g.height-10,)

    def Draw(self):
        if self.showfps: self.fps.draw()
        #self.heart.draw()
        #self.score.draw()
        self.l_lives.draw()
        self.l_score.draw()
        if self.g.state & self.g.PAUSE:
            self.screen.draw()
            self.l_pause.draw()
        elif self.g.state & self.g.GAMEOVER:
            self.screen.draw()
            self.l_gameover.draw()
        elif self.g.state & self.g.PRE:
            self.screen.draw()
            self.l_level.draw()
